<?php


namespace app\common\lib\sms;

require_once '../vendor/services.php';
use TencentCloud\Common\Credential;
use TencentCloud\Common\Profile\ClientProfile;
use TencentCloud\Common\Profile\HttpProfile;
use TencentCloud\Common\Exception\TencentCloudSDKException;
use TencentCloud\Sms\V20190711\SmsClient;
use TencentCloud\Sms\V20190711\Models\SendSmsRequest;
class TencentSms
{
    public static function sendCode($phone,$code){
        try {
            $cred = new Credential("AKIDcz60xqn3YYJ3xbEMM7ds0tWu4A3hr0HK", "2oOaX1GUUesrpaL5Zu4rzud7dx1A62OZ");
            $httpProfile = new HttpProfile();
            $httpProfile->setEndpoint("sms.tencentcloudapi.com");

            $clientProfile = new ClientProfile();
            $clientProfile->setHttpProfile($httpProfile);
            $client = new SmsClient($cred, "", $clientProfile);

            $req = new SendSmsRequest();

            $params = array(
                "PhoneNumberSet" => array( "+86".$phone ),
                "TemplateID" => "927529",
                "Sign" => "容慧科技IT",
                "TemplateParamSet" => array( strval($code)),
                "SmsSdkAppid" => "1400510207"
            );
            $req->fromJsonString(json_encode($params));

            $resp = $client->SendSms($req);
//            dump($resp->SendStatusSet[0]->Fee);exit();
            return $resp;
//            print_r($resp->toJsonString());
        }
        catch(TencentCloudSDKException $e) {
            echo $e;
            return $e;
        }
    }
}